/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Components;


import Components.Templates.Entity;
import java.awt.Point;


import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Shape;


import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;

import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import org.newdawn.slick.tiled.TiledMap;
import org.newdawn.slick.tiled.TileSet;

import java.util.ArrayList;

import Helper.Tile;




public class Player extends Entity{

    private int tileSizeX = 64;
    private int tileSizeY = 64;
    private int pic = 0; 
    private int testing = 0;   
    
    private double x = 100;
    private double y = 100;
    private double goX = 0;
    private double goY = 10;
    private double jumpFY = 1;
        
    private Boolean jump = false;
    private Boolean rejump = false;
	
    protected final Shape colModel = new Rectangle((int)x,(int)y,50,100);
    
    private ArrayList<Image> tileArray = new ArrayList();

    private Tile tile = new Tile();
    
    
    
    
    public Player(int ID){
	super(ID);
    }
    


    @Override
    public int getID() {
	return ID;
    }

    @Override
    public void init(GameContainer container, StateBasedGame game) throws SlickException {
	
	tileArray = tile.getTiles("/data/Tiles/Entitys/Player/test.png", tileSizeX, tileSizeY);
	
    }

    @Override
    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
	
	((Image)(tileArray.get(pic))).draw((int)x, (int)y);
	
	
    }

    @Override
    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
	
	testing += delta;
	if(testing >= 250 & container.getInput().isKeyDown(Input.KEY_H)){
	    pic = ((int)(pic+1))%3;
	    testing = 0;
	}	
	
	if(y > 298 & container.getInput().isKeyDown(Input.KEY_SPACE)){
	    jump = true;
	}
	
	
	
	if(jump & rejump){
	    goY -= jumpFY;
	    jumpFY += jumpFY;
	    if(jumpFY > 8){
		jump = false;
		jumpFY = 1;
		rejump = false;
	    }
	}else{
	    jump = false;
	}
	
	if(y > 399 & !jump & !container.getInput().isKeyDown(Input.KEY_SPACE)){
	    rejump = true;
	}
	
	
	
	if(goY < 5){
	    goY+=0.5;
	}
	
	
	for(int i = 0 ;goY > 0 & y+goY-i> 400 ; i+= 1){
	    goY = i;
	}
	

	if(container.getInput().isKeyDown(Input.KEY_D) & goX < 5 & goX >= 0){
	    goX += 0.02;
	}else if(container.getInput().isKeyDown(Input.KEY_A) & goX > -5 & goX <= 0){
	    goX += -0.02;    
	}if(container.getInput().isKeyDown(Input.KEY_D) & goX < 0){
	    goX = 0;
	}if(container.getInput().isKeyDown(Input.KEY_A) & goX > 0){
	    goX = 0;   
	}else if(!container.getInput().isKeyDown(Input.KEY_A) & !container.getInput().isKeyDown(Input.KEY_D)){
	    goX /= 1.05;
	    
	}
	
	
	
	x += goX;
	
	
	y += goY;
	
	x = x%640;
    }

    @Override
    public void setNewInput(int newInput) {
	IO_SYSTEM.add(newInput);
    }

    @Override
    public void removeInput(int input) {
	IO_SYSTEM.remove(input);
	
    }

    @Override
    public void setNewOutput(int newOutput) {
	throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeOutput(int ouput) {
	throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void getInput(int input, Object owner) {
	throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int fireOutput(Object target) {
	throw new UnsupportedOperationException("Not supported yet.");
    }


    
    
    
}
